package com.ykzhujiang.lovespirit;

import java.io.IOException;
import java.util.Date;
import java.util.logging.Logger;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.ykzhujiang.lovespirit.entity.Comment;
import com.ykzhujiang.lovespirit.util.DataManager;
import com.ykzhujiang.lovespirit.util.Utility;

public class CommentServlet extends HttpServlet {
	private static final Logger logger = Logger.getLogger(CommentServlet.class
			.getName());

	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		UserService userService = UserServiceFactory.getUserService();
		User user = userService.getCurrentUser();

		String content = req.getParameter("content");
		String src = req.getParameter("src");
		if (user == null || content == null || src == null) {
			resp.sendRedirect("/");
			return;
		}
		Date date = new Date();
		content = Utility.RemoveHTMLTag(content);
		Comment comment = new Comment(user, content, date, src);

		DataManager.addData(comment);
		//resp.sendRedirect("/");
	}
}